package com.mccree.cloud.common;

import cn.hutool.http.HttpStatus;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @Author: MccRee
 * @Date: 2022/6/1 10:13
 */
@Data
@Accessors(chain = true)
public class R <T>{
    private T data;

    private int code;

    private String msg;

    public static R error() {
        return error(HttpStatus.HTTP_INTERNAL_ERROR, "服务器内部错误,请联系管理员!");
    }

    public static R error(String msg) {
        return error(HttpStatus.HTTP_INTERNAL_ERROR, msg);
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.setCode(code).setMsg(msg);
        return r;
    }

    public static R ok(String msg) {
        R r = new R();
        return r.setMsg(msg).setCode(200);
    }

    public static R ok(Object data) {
        R r = new R();
        return r.setData(data).setCode(200).setMsg("success");
    }

    public static R ok(Object data,String msg) {
        R r = new R();
        return r.setData(data).setCode(200).setMsg(msg);
    }

    public static R ok() {
        return new R().setCode(200).setMsg("success");
    }
}
